package com.dd.cloud.common.enums;


import com.dd.cloud.common.vo.EnumResultVo;

/**
 * @author zk
 */
public enum ZkResponseEnum implements ExceptionEnumInterface{
    SUCCESS(2000, "成功"),
    ACCEPT_MULTIPLE_REQUEST_METHOD(3000, "接口接受多个请求方式"),
    ONLY_ACCEPT_GET(3001, "接口只接受GET请求"),
    ONLY_ACCEPT_POST(3002, "接口只接受POST请求"),
    REQUEST_ERROR(4000, "参数缺失:%s"),
    POST_BODY_RESOLVE_ERROR(4000, "POST请求中Body数据解析失败"),
    MECHAN_IS_NOT_FOUND(4000, "机构不存在"),
    MECHAN_IS_DISABLE(4000, "机构被禁用"),
    SIGN_INVALID(4000, "签名失效"),
    SIGN_ERROR(4000, "签名验证失败"),
    LACK_PARAMETER(4001, "参数缺失"),
    ORDER_IS_EXISTS(4002, "订单号已存在"),
    START_DATE_CAN_NOT_BEFORE_NOW(4003, "服务开始日期不能在当前日期之前"),
    SAVU_DEP_FAIL(4004, "添加订购数据失败"),
    ORDER_IS_NOT_EXISTS(4005, "订单号不存在"),
    ORDER_IS_REFUND(4006, "该订单已退款"),
    ORDER_IS_OVERDUE(4007, "该订单服务已过期"),

    ORDER_REFUND_ERROR(5001, "订单退订失败,原因:%s"),
    SYSTEM_ERROR(5000, "系统错误");

    ZkResponseEnum(int code, String body) {
        this.code = code;
        this.body = body;
    }

    private int code;
    private String body;

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getBody() {
        return body;
    }

    public void setBody(String body) {
        this.body = body;
    }

    /**
     * 返回异常信息
     * @return
     */
    @Override
    public EnumResultVo getMessage() {
        ZkResponseEnum zkExceptionEnum = ZkResponseEnum.valueOf(this.name());
        return new EnumResultVo(zkExceptionEnum.code, zkExceptionEnum.body);
    }

    /**
     * 设置补充异常信息
     * @param msg
     */
    @Override
    public String setMessage(String msg) {
        ZkResponseEnum zkExceptionEnum = ZkResponseEnum.valueOf(this.name());
        return String.format(zkExceptionEnum.getBody(),msg);
    }
}
